package com.hellobike.haxing.modules.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hellobike.haxing.common.vo.Result;
import com.hellobike.haxing.common.system.query.QueryGenerator;
import com.hellobike.haxing.common.util.oConvertUtils;
import com.hellobike.haxing.modules.product.entity.SkuStock;
import com.hellobike.haxing.modules.product.service.ISkuStockService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import com.hellobike.haxing.common.system.base.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import com.hellobike.haxing.common.annotation.AutoLog;

/**
 * @Description: 销售库存
 * @Author: haxing-boot
 * @Date: 2020-02-10
 * @Version: V1.0
 */
@RestController
@RequestMapping("/product/skuStock")
@Slf4j
public class SkuStockController extends BaseController<SkuStock, ISkuStockService> {
    @Autowired
    private ISkuStockService skuStockService;

    /**
     * 某城市下某些sku的销售库存
     *
     * @param cityId
     * @param skuIds
     * @return
     */
    @GetMapping("/citySkuStocks")
    public Result getCitySkuStocks(@RequestParam(name = "cityId", required = true) Long cityId,
                                   @RequestParam(name = "skuIds", required = true) String skuIds) {
        QueryWrapper<SkuStock> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SkuStock::getCityId, cityId).in(SkuStock::getSkuId, Arrays.asList(skuIds.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList()));
        List<SkuStock> skuStocks = skuStockService.list(queryWrapper);
        return Result.ok(skuStocks);
    }

    /**
     * 增减库存
     *
     * @param cityId
     * @param skuId
     * @param changeNum
     * @return
     */
    @GetMapping("/changeCitySkuStock")
    public Result changeCitySkuStock(@RequestParam(name = "cityId", required = true) Long cityId,
                                     @RequestParam(name = "skuId", required = true) Long skuId,
                                     @RequestParam(name = "changeNum", required = true) Integer changeNum) {
        return skuStockService.changeCitySkuStock(cityId, skuId, changeNum);
    }

}
